<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>合同修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../resources/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../../../resources/css/style.css"  media="all">

    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>
        .layui-input-block{margin-bottom:20px;}
        .layui-form-label{padding: 9px 0;width: auto;}
        .marg_R{margin-right: 22px;width: 100%;}
        .layui-form-item{text-align: center;}
        .layui-input{width: 100%;}
        .layui-form-select{width: 100%;}
        .layui-inline{width: 100%;}
        .layui-input-inline{width: 88%;}
        @media screen and (max-width: 1280px){
            .layui-input-inline{width: 82%;}

        }
        .maskon, .masksx{height: 50%; width: 80%;}
    </style>
</head>
<body>


<form class="layui-form tianjiaqiye" method="post" action="">
    <div class="layui-row">
        <div class="layui-col-md1">
            <span class="layui-btn" onclick="history.back(-1);"><i class="layui-icon"></i></span>
        </div>
        <div class="layui-col-md2">
            <label class="layui-form-label">转换为顶管合同</label>
            <div class="layui-input-block">
                <input type="checkbox" id="dght" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
            </div>
        </div>
    </div>
    <table class="layui-table">
        <tbody>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">编号:</label>
                    <div class="layui-input-block">
                        <input type="text" name="cc_code"  lay-verify="required" autocomplete="off" placeholder="请输入工程编号" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <label class="layui-form-label">工程名称:</label>
                <div class="layui-input-block">
                    <input type="text" name="eppname"  lay-verify="required" autocomplete="off" placeholder="请输入工程名称" class="layui-input">
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <label class="layui-form-label">起止点:</label>
                <div class="layui-input-block">
                    <input type="text" name="eppstaend"  lay-verify="required" autocomplete="off" placeholder="请输入起止点" class="layui-input">
                </div>
            </td>
            <td>
                <div class="layui-inline">
                    <label class="layui-form-label"><span class="bixuan">*</span>建设单位：</label>
                    <div class="layui-input-block " lay-filter='compjs'>
                        <select name="compjs" lay-verify="required" lay-search="" lay-filter="test1" class="compjs">

                        </select>
                        <!--<input type="text" name="compname1" value="硂鑫" hidden />-->
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-inline">
                    <label class="layui-form-label"><span class="bixuan">*</span>施工单位：</label>
                    <div class="layui-input-block ">
                        <select name="compname1" lay-verify="required" lay-filter="test" lay-search="" class="compcode1" >

                        </select>
                        <input type="text" name="compcode1" value="" hidden />
                    </div>
                </div>
            </td>
            <td>
                <label class="layui-form-label">项目负责人：</label>
                <div class="layui-input-block">
                    <input type="text" name="compperson1"  lay-verify="required" autocomplete="off" placeholder="请输入项目负责人" class="layui-input">
                </div>
                <label class="layui-form-label">联系方式：</label>
                <div class="layui-input-block">
                    <input type="text" name="comptel1" lay-verify="required" autocomplete="off" placeholder="请输入联系方式" class="layui-input">
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-inline marg_R">
                    <label class="layui-form-label">计划开工日期</label>
                    <div class="layui-input-block">
                        <input type="text" name="prestatime" class="layui-input" lay-verify="required" id="test-limit1" placeholder="yyyy-MM-dd">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-inline marg_R">
                    <label class="layui-form-label">竣工时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="preendtime" class="layui-input" lay-verify="required" id="test-limit2" placeholder="yyyy-MM-dd">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <div class="layui-inline marg_R">
                    <label class="layui-form-label">
                        <span class="bixuan">*</span>
                        合同签订时间
                    </label>
                    <div class="layui-input-block">
                        <input type="text" name="signtime" lay-verify="required" class="layui-input" id="test-limit00" placeholder="yyyy-MM-dd">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-inline">
                    <label class="layui-form-label"><span class="bixuan">*</span>委托设计单位：</label>
                    <div class="layui-input-block ">
                        <select name="compname0" lay-verify="required" lay-filter="test1" lay-search=""
                                class="compname0">

                        </select>
                        <!--<input type="text" name="compname0" value="硂鑫" hidden />-->
                    </div>
                </div>
                <!--<div class="layui-inline">-->
                    <!--<label class="layui-form-label">：</label>-->
                    <!--<div class="layui-input-inline" style="margin-left: 20px;">-->
                        <!--<select name="" lay-verify="required" lay-search="" class="">-->


                        <!--</select>-->
                    <!--</div>-->
                <!--</div>-->
            </td>
            <td>
                <label class="layui-form-label">项目负责人：</label>
                <div class="layui-input-block">
                    <input type="text" name="compperson0"  lay-verify="required" autocomplete="off" placeholder="请输入项目负责人" class="layui-input">
                </div>
                <label class="layui-form-label">联系方式：</label>
                <div class="layui-input-block">
                    <input type="text" name="comptel0"  lay-verify="required" autocomplete="off" placeholder="请输入联系方式" class="layui-input">
                </div>
            </td>
        </tr>
        <tr>
            <td class="zhezhao"  colspan="2">
                <label class="layui-form-label"><span class="bixuan">*</span>工程概况</label>
                <div class="layui-input-block">
                    <textarea name="ccBuil" placeholder="请输入工程概况" lay-verify="required" class="layui-textarea survey" disabled="disabled" value="aaaa"></textarea>
                    <input type="text" name="ccBuil" value="" class="survey" hidden/>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label"><span class="bixuan">*</span>合同单价</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入合同单价" name="cc_price" lay-verify="required" class="layui-textarea" ></textarea>
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td class="zhezhaos"  colspan="2">
                <label class="layui-form-label"><span class="bixuan">*</span>工程费用</label>
                <div class="layui-input-block">
                    <textarea name="gcfy" placeholder="请输入内容" lay-verify="required" class="layui-textarea desc" disabled="disabled"></textarea>
                    <input type="text" name="gcfy" value="" class="desc" hidden/>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <label class="layui-form-label"><span class="bixuan">*</span>文明、环保施工：</label>
                <div class="layui-input-block">
                    <textarea name="cc_culture" placeholder="请输入内容" lay-verify="required" class="layui-textarea" >根据甲方要求设置围挡及工程宣传标语等设施，做到环保文明施工，不扰民。施工管理人员要佩戴胸卡不得无故离开施工场地。同时符合主体施工单位的相关要求。</textarea>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <label class="layui-form-label"><span class="bixuan">*</span>材料供应：</label>
                <div class="layui-input-block">
                    <textarea name="cc_material" placeholder="请输入内容"  lay-verify="required" class="layui-textarea" ></textarea>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <label class="layui-form-label">竣工验收：</label>
                <div class="layui-input-block">
                    <textarea name="cc_finve" placeholder="请输入内容" lay-verify="required" class="layui-textarea" ></textarea>

                </div>

            </td>
        </tr>
        <tr>
            <td>
                <label class="layui-form-label">工程质量：</label>
                <div class="layui-input-block">
                    <input type="text" name="cc_buildmass"  lay-verify="required" autocomplete="off" placeholder="请输入工程质量" class="layui-input" value="严格按照设计图纸施工，符合国家通信行业标准及甲方和主体监理的管理要求。">
                </div>
            </td>
            <td>
                <label class="layui-form-label">安全施工：</label>
                <div class="layui-input-block">
                    <input type="text" name="cc_security"  lay-verify="required" autocomplete="off" placeholder="请输入项目负责人" class="layui-input" value="符合国家（部）相关技术、安全规范和甲方要求，因违规操作造成安全事故的一切后果均由乙方承担。">
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <label class="layui-form-label">决算方式：</label>
                <div class="layui-input-block">
                    <input type="text" name="cc_costtype"  lay-verify="required" autocomplete="off" placeholder="请输入决算方式" class="layui-input">
                </div>
            </td>
            <td>
                <label class="layui-form-label">质保期限：</label>
                <div class="layui-input-block">
                    <input type="text" name="cc_warrantytime"  lay-verify="required" autocomplete="off" placeholder="请输入工程质量" class="layui-input" value="质保期限为1年，以工程竣工验收合格之日起计算。">
                </div>
            </td>
        </tr>
        <tr>

            <td colspan="2">
                <label class="layui-form-label">其他：</label>
                <div class="layui-input-block">
                    <textarea name="cc_other" placeholder="请输入内容" class="layui-textarea" ></textarea>

                </div>
            </td>
        </tr>
        <input type="hidden" value="1970-01-01 00:00:00" name="sttime" />
        <input type="hidden" value="1970-01-01 00:00:00" name="comtime" />
        <input type="hidden" value="1970-01-01 00:00:00" name="cptime" />
        <input type="hidden" value="0" name="state" />
        <input type="hidden" value="0" name="cc_uuid" />
        <input type="hidden" value=""  name="ccPrice" />
        </tbody>
    </table>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn tijiao" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>
</form>
<div class="mask">
    <div class="maskon maskonsp" style="overflow: hidden;">
        <div class="title"><span class="titleL">工程概况</span><span class="close">×</span></div>
        <div class="forms">
            <div class="maskmain">
                <p class="tianjia"><button class="layui-btn">增加</button></p>
                <table>
                    <thead>
                    <tr>
                        <th>项目名称</th>
                        <th>单价</th>
                        <th>数量</th>
                        <th>计量单位</th>
                        <th>结算类型</th>
                    </tr>
                    </thead>
                    <tbody class="mask_tbody">
                    <tr class="datas">
                        <td><input type="text" name="key" class="key" style="width: 130px !important;"/></td>
                        <td class="danjias"><input type="number" name="vals" class="vals" style="width: 125px !important;"/>(万元)</td>
                        <td class="nums"><input type="number" name="val" class="valN" style="width: 130px !important;"/></td>
                        <td><input type="text" name="val" class="valz" style="width: 125px !important;"/></td>
                        <td class="selects">
                            <select name="modules" lay-verify="required" lay-search="">
                                <option value="0">开槽施工造价</option>
                                <option value="1">人手井造价</option>

                            </select>
                        </td>
                        <td><span class="shanchu">×</span></td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <button type="button" class="yes" style="margin-bottom: 10px;">确定</button>
        </div>
    </div>
</div><!--工程概况弹框-->

<script src="../../../resources/layui/layui.js" charset="utf-8"></script>
<script src="../../../resources/js/style.js"></script>
<script src="../../../resources/js/api.js"></script>
<script>
    //Demo

    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        var textareadata='';        //传递mark弹框的内容给textarea框

        var kaicao=0;     //开槽施工造价
        var renshoujing=0;     //人手井造价


        var newOBJ=JSON.parse(sessionStorage.xialaCont);                //获取上个页面传递的json字符串
        console.log(newOBJ)
        var jianse=newOBJ.c1;
        var shigong=newOBJ.c2;
        var sheji=newOBJ.c4;


        for(var i=0;i<jianse.length;i++){
            $('[name="compjs"]').append('<option value="'+jianse[i].compName+'">'+jianse[i].compName+'</option>')
        }
        for(var i=0;i<shigong.length;i++){
            $('[name="compname1"]').append('<option value="'+shigong[i].compName+'" code="'+shigong[i].compid+'">'+shigong[i].compName+'</option>')
        }
        for(var i=0;i<sheji.length;i++){
            $('[name="compname0"]').append('<option value="'+sheji[i].compName+'">'+sheji[i].compName+'</option>')
        }
        form.render();

        form.on('select(test)', function(data){
            console.log(data.value); //得到被选中的值
           $('[name="compcode1"]').val(data.value);
            $.each(shigong,function (k,v) {
                console.log(shigong)
                if(data.value==v.compName){
                    $('[name="compperson1"]').val(v.director);
                    $('[name="comptel1"]').val(v.dmotel);
                }

            })

        });
        form.on('select(test1)', function(data){
            console.log(data.value); //得到被选中的值
            $('[name="compcode1"]').val(data.value);
            $.each(sheji,function (k,v) {
                console.log(sheji)
                if(data.value==v.compName){
                    $('[name="compperson0"]').val(v.director);
                    $('[name="comptel0"]').val(v.dmotel);
                }

            })

        });
        var ourCode='';

        var inputs=new Object;                //新建对象用来接受工程概况参数  动态渲染添加弹框层的input框以及数据填充；
        var inputtow=new Object;                //新建对象用来接受工程费用参数  动态渲染添加弹框层的input框以及数据填充；
        ajaxs('/api/contract/loadContractDetails.do','post',{'uuid':sessionStorage.id,'p':getCookie('yanzheng')},function (data) {
            console.log(data,'<<<<<<<<<<<<<<<<<<<<')
            inputs=data.data[2];
            inputtow=data.data[2];
            var gongchenggaikuo='';
            var gongchengfeiyong='';
            for(var i=0;i<data.data[2].length;i++){
                console.log("遍 >>> " + data.data[2][i].cc_key,data.data[2][i].cc_value)
                gongchenggaikuo+=data.data[2][i].cc_cname;
                gongchenggaikuo+=',';
                gongchenggaikuo+=data.data[2][i].cc_cnum;
                gongchenggaikuo+=',';
                gongchenggaikuo+=data.data[2][i].cc_cbit;
                gongchenggaikuo+='|';
            }
            gongchenggaikuo=gongchenggaikuo.substr(0,gongchenggaikuo.length-1)           //清除最后标点
            for(var i=0;i<data.data[2].length;i++){
                gongchengfeiyong+=data.data[2][i].cc_cname;
                gongchengfeiyong+=',';
                gongchengfeiyong+=data.data[2][i].cc_cprice;
                gongchengfeiyong+=',';
                gongchengfeiyong+=data.data[2][i].cc_cnum;
                gongchengfeiyong+=',';
                gongchengfeiyong+=data.data[2][i].cc_cbit;
                gongchengfeiyong+='|';
            }
            gongchengfeiyong=gongchengfeiyong.substr(0,gongchengfeiyong.length-1)           //清除最后标点
            var datas=data.data[0][0];             //获取数据
            if(data.code=='0'){
                $("[name='cc_code']").val(datas.cc_Code);
                $("[name='eppname']").val(datas.eppName);
                $("[name='eppstaend']").val(datas.eppStaEnd);
                $("[name='compperson1']").val(datas.compPerson1);
                $("[name='comptel1']").val(datas.compTel1);
                $("[name='prestatime']").val(datas.preStaTime);
                $("[name='preendtime']").val(datas.preEndTime);
                $("[name='compperson0']").val(datas.compPerson0);
                $("[name='comptel0']").val(datas.compTel0);
                $("[name='cc_price']").val(datas.cc_Price);
                $("[name='ccBuil']").val(gongchenggaikuo);
                $("[name='ccPrice']").val(gongchengfeiyong);                    //待处理
                $("[name='cc_culture']").val(datas.cc_Culture);
                $("[name='cc_material']").val(datas.cc_Material);
                $("[name='cc_finve']").val(datas.cc_FinVe);
                $("[name='cc_buildmass']").val(datas.cc_BuildMass);
                $("[name='cc_security']").val(datas.cc_Security);
                $("[name='cc_costtype']").val(datas.cc_CostType);
                $("[name='cc_warrantytime']").val(datas.cc_WarrantyTime);
                $("[name='cc_other']").val(datas.cc_Other);
                $("[name='cc_uuid']").val(datas.cc_UUID);
                $("[name='signtime']").val(datas.sign_Time);
                $('[name="compname0"]').val(datas.compName0);
                $('[name="compname1"]').val(datas.compName1);
                $('[name="gcfy"]').val(datas.gcfy);
                $('.compcode1').val(datas.compName1);
                ourCode=datas.cc_Code;
                kaicao=datas.oprice;
                renshoujing=datas.hprice;
                $('.desc').val()
                var  times;
                clearInterval(times);
                    $("[name='compjs']").val(datas.compJs);
                    form.render('select')
            }else{
                layer.msg('获取数据失败，请重试');
                setTimeout(function () {
                    javascript:history.back(-1)
                },3000)
            }
        });
        //日期
        laydate.render({
            elem: '#date'
            ,type:'datetime'
        });
        laydate.render({
            elem: '#date1'
            ,type:'datetime'

        });
        laydate.render({
            elem: '#test-limit00'
            ,type:'datetime'
        });
        $('input').each(function () {                       //匹配所有input框  属性为必填的项添加*标识符
            if($(this).attr('lay-verify')=="required"){
                $(this).parent().prev().prepend('<span class="bixuan">*</span>')
            }
        });
        panduanshijian('#test-limit1','#test-limit2',0,1000,'.layui-btn-primary');      //计划开工时间和竣工时间判断
        function currentzhezhao(classname,zhezhao){
            $(document).on('click',classname,function (e) {


                $(zhezhao).show();          //遮罩层出现

                $(zhezhao).children($("[readonly!='readonly']")).val('');          //清空弹框input内容
//                $('.val').val('');          //清空弹框input内容
                if(classname=='.zhezhao'){
                    if(!window.firstAppend){
                        window.firstAppend = true;
                        console.log(inputs, ':::::::::::::::::::');
                        $('.mask .mask_tbody').html('');                //清除所有的input 重新填充
                        for(var i=0;i<inputs.length;i++){
                            var n=inputs[i].cc_cname;
                            var shu=0;
                            if(n.indexOf('直')==1||n.indexOf('梅')==1){
                                shu=0;
                            }else{
                                shu=1;
                            }
                            $('.mask .mask_tbody').append(' <tr class="datas">\n' +
                                '                    <td><input type="text" name="key" class="key" style="width:130px !important;          " value="'+inputs[i].cc_cname+'"/></td>\n' +
                                '                      <td class="danjias"><input type="text" name="val" class="vals" style="width:130px !important; " value="'+inputs[i].cc_cprice+'"/>(万元)</tdc>\n' +
                                '                      <td class="nums"><input type="text" name="val" class="valN" style="width:130px !important; " value="'+inputs[i].cc_cnum+'"/></td>\n' +
                                '                      <td><input type="text" name="val" class="valz" style="width:130px !important; " value="'+inputs[i].cc_cbit+'"/></td>\n' +
                                    '<td class="selects">\n' +
                                '                            <select name="modules" value="'+shu+'" lay-verify="required" lay-search="">\n' +
                                '                                <option value="0">开槽施工造价</option>\n' +
                                '                                <option value="1">人手井造价</option>\n' +
                                '\n' +
                                '                            </select>\n' +
                                '                        </td>'+
                                '                    <td><span class="shanchu">×</span></td>\n' +
                                '                </tr>')
                        }

                    }
                };
                $('[name="modules"]').each(function (e) {
                    this.value=$(this).attr('value');
                })
                textareadata='';            //字符串清空
            });
        }
        //监听指定开关
        form.on('switch(switchTest)', function(data){
            var hm = "";
            if( this.checked ){
                //2018-6-5 16:01:54  合同
                //hm = "合同单价（含税11%）： 单项通讯管道顶管工程400孔•米（含）以内 92元/孔•米，单项通讯管道顶管工程超过400孔•米（不含）以上部分 82 元/孔•米；砖砌手孔  2600 元/座（不含钢筋砼上覆费用）；砖砌小号直通型人孔3600元/座（不含钢筋砼上覆费用）；异型人孔5000元/座（不含钢筋砼上覆费用）。";
                hm = "合同单价：单项通讯管道顶管工程400孔·米（含）以内82.88元/孔·米，单项通讯管道顶管工程超过400孔·米（不含）以上部分73.87元/孔·米；砖砌手孔2342.34元/座（不含钢筋砼上覆费用）；砖砌小号直通型人孔3243.24元/座（不含钢筋砼上覆费用）；异型人孔4504.5元/座（不含钢筋砼上覆费用）。"
            }else {
                hm = "合同单价一(价税合计)：铺设通讯管线工程(2-7孔) 13.7643万元/路由·公里；合同单价二(价税合计)：铺设通讯管线工程(8-11) 15.2504万元/路由·公里；合同单价三(价税合计)：铺设通讯管线工程(12-24) 16.3432万元/路由·公里；合同单价四(价税合计)：砖砌手孔 2600元/座 （不含钢筋砼上覆费用）；合同单价五(价税合计)：砖砌小号直通型人孔 3600元/座 （不含钢筋砼上覆费用）；合同单价六(价税合计)：异型人孔 5000元/座 （不含钢筋砼上覆费用）；";
            }
            $("[name='cc_price']").val(hm);
            layer.tips('更改成功~', data.othis)
        });

        currentzhezhao('.zhezhao','.mask')          //工程概况调用弹框
//        currentzhezhao('.zhezhaos','.masktow')      //工程费用调用弹框
        /*--------------->遮罩层内容*/
        $('.close').click(function () {
            $('.mask').hide();          //关闭遮罩层
            $('.masktow').hide();          //关闭遮罩层
        })
        $('.tianjia').click(function () {       //  点击增加input 框
            $('.maskmain .mask_tbody').append('<tr class="datas">\n' +
                '                        <td><input type="text" name="key" style="width: 130px !important;" class="key" /></td>\n' +
                '                        <td class="danjias"><input type="number" name="val" class="vals" style="width: 130px !important;" class="val"/>(万元)</td>\n' +
                '                        <td class="nums"><input type="number" name="val" class="valN" style="width: 130px !important;" class="val"/></td>\n' +
                '                        <td><input type="text" name="val" class="valz" style="width: 130px !important;" class="val"/></td>\n' +
                    '<td class="selects">\n' +
                '                            <select name="modules" lay-verify="required" lay-search="">\n' +
                '                                <option value="0">开槽施工造价</option>\n' +
                '                                <option value="1">人手井造价</option>\n' +
                '\n' +
                '                            </select>\n' +
                '                        </td>'+
                '                        <td><span class="shanchu">×</span></td>\n' +
                '                    </tr>')
        });                //工程概况 点击添加
        $('.tianjias').click(function () {       //  点击增加input 框
            $('.maskmain .masktow_tbody').append('  <tr class="datas">\n' +
                '                    <td><input type="text" name="names" class="val"/></td>\n' +
                '                      <td><input type="number" name="unitPrice" class="val"/></td>\n' +
                '                    <td><input type="number" name="number" class="val"/></td>\n' +
                '                    <td><input type="text" name="company" class="val"/></td>\n' +
                    '<td class="selects">\n' +
                '                            <select name="modules" lay-verify="required" lay-search="">\n' +
                '                                <option value="0">开槽施工造价</option>\n' +
                '                                <option value="1">人手井造价</option>\n' +
                '\n' +
                '                            </select>\n' +
                '                        </td>'+
                '                    <td><span class="shanchu">×</span></td>\n' +
                '                </tr>')
        });            //工程费用 点击添加
        $(document).on('click','.shanchu',function () {
            var _this=$(this).parent().parent()      //找到要删除的行
            _this.remove()                          //删除
        });
        //金额小写转大写
        function changeMoneyToChinese(money){
            var cnNums = new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"); //汉字的数字
            var cnIntRadice = new Array("","拾","佰","仟"); //基本单位
            var cnIntUnits = new Array("","万","亿","兆"); //对应整数部分扩展单位
            var cnDecUnits = new Array("角","分","毫","厘"); //对应小数部分单位
            //var cnInteger = "整"; //整数金额时后面跟的字符
            var cnIntLast = "元"; //整型完以后的单位
            var maxNum = 999999999999999.9999; //最大处理的数字

            var IntegerNum; //金额整数部分
            var DecimalNum; //金额小数部分
            var ChineseStr=""; //输出的中文金额字符串
            var parts; //分离金额后用的数组，预定义
            if( money == "" ){
                return "";
            }
            money = parseFloat(money);
            console.log(money,'我是要循环的')

            if( money >= maxNum ){
                $.alert('超出最大处理数字');
                return "";
            }
            if( money == 0 ){
                //ChineseStr = cnNums[0]+cnIntLast+cnInteger;
                ChineseStr = cnNums[0]+cnIntLast
                //document.getElementById("show").value=ChineseStr;
                return ChineseStr;
            }
            money = money.toString(); //转换为字符串

            if( money.indexOf(".") == -1 ){
                IntegerNum = money;
                DecimalNum = '';
            }else{
                parts = money.split(".");
                IntegerNum = parts[0];
                DecimalNum = parts[1].substr(0,4);
            }
            if( parseInt(IntegerNum,10) > 0 ){//获取整型部分转换
                zeroCount = 0;
                IntLen = IntegerNum.length;
                for( i=0;i<IntLen;i++ ){
                    n = IntegerNum.substr(i,1);
                    console.log(n,'我是N')
                    p = IntLen - i - 1;
                    q = p / 4;
                    m = p % 4;
                    if( n == "0" ){
                        zeroCount++;
                    }else{
                        if( zeroCount > 0 ){
                            ChineseStr += cnNums[0];
                        }
                        zeroCount = 0; //归零
                        ChineseStr += cnNums[parseInt(n)]+cnIntRadice[m];
                    }
                    if( m==0 && zeroCount<4 ){
                        ChineseStr += cnIntUnits[q];
                    }
                    console.log(ChineseStr)

                }
                ChineseStr += cnIntLast;

                //整型部分处理完毕
            }
//            if( DecimalNum!= '' ){//小数部分
//                decLen = DecimalNum.length;
//                for( i=0; i<decLen; i++ ){
//                    n = DecimalNum.substr(i,1);
//                    if( n != '0' ){
//                        ChineseStr += cnNums[Number(n)]+cnDecUnits[i];
//                    }
//                }
//            }
            if( ChineseStr == '' ){
                //ChineseStr += cnNums[0]+cnIntLast+cnInteger;
                ChineseStr += cnNums[0]+cnIntLast;
            }/* else if( DecimalNum == '' ){
                ChineseStr += cnInteger;
                ChineseStr += cnInteger;
            } */
            return ChineseStr;
        }
//http://www.huangweipeng.org/Workaround-JS-floating-point-decimal-operation-appeared-of-Bug.html 参考
        function accMul(arg1,arg2)
        {
            var m=0,s1=arg1.toString(),s2=arg2.toString();
            try{m+=s1.split(".")[1].length}catch(e){}
            try{m+=s2.split(".")[1].length}catch(e){}
            return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
        }

        $('.yes').click(function () {
            var _datas=$('.datas');
            var beatterArray = [];

            var _parentName=($(this).parent().parent().prop("className"));      //获取遮罩层名称
            if(_parentName=='masktow'){

                for(var j=0;j<$('.masktow .datas').length;j++) {
                    var _val=$('.masktow .datas').eq(j).children('td').children('.val')
                    console.log(_val)
                    for(var i=0;i<_val.length;i++){
                        console.log(_val.eq(i).children('input').val()!='')
                        if(_val.eq(i).val()!=''){
                            textareadata+=_val.eq(i).val()+',';
                        }else{
                            layer.msg('请填写完整页面信息');
                            return;
                        }
                    }
                    textareadata=textareadata.substr(0,textareadata.length-1)           //清除最后标点
                    textareadata+='|'
                }
                textareadata=textareadata.substr(0,textareadata.length-1)           //清除最后标点
                console.log(textareadata)

                $('.masktow').hide();          //隐藏遮罩层

                $('.desc').val(textareadata);
            }else{
                var gongchengFY='';
                textareadata = '';
                var gongchengKC=0;         //开槽施工造价
                var gongchengRS=0;         //人手井造价
                var pan=true;
                $('.maskonsp').find('.datas').each(function (k ,v) {
                    var g = [];     //接受工程概况的参数;
                    var S=[];       //接受工程费用的参数;
                    var z=$(v).children('.selects').children('select').val();
                    var danjia=$(v).children('.danjias').children('input').val();
                    var nums=$(v).children('.nums').children('input').val();
                    if(z==0){
                        gongchengKC+=parseFloat(danjia)*parseFloat(nums);
                        kaicao=gongchengKC.toFixed(4);
                    }else{
                        gongchengRS+=parseFloat(danjia)*parseFloat(nums);
                        renshoujing=gongchengRS.toFixed(4);

                    };

                    $(v).find('input').each(function (k ,v) {
                        S.push(v.value)
                        if($(v).is('.vals')){
                            return;
                        }
                        g.push(v.value);
                    });

                    $('.maskonsp').find('input').each(function (k,v) {
                        if($(this).val()){
                            pan=true;
                        }else{
                            layer.msg('页面信息不能为空');
                            pan=false;
                            return false;
                        }
                    })

                    if(!pan){
                        return;
                    }

                    gongchengFY+=S.join(',')+'|';

                    textareadata += g.join(',')+'|';
                })
                if(!pan){
                    return;
                }

                textareadata=textareadata.substr(0,textareadata.length-1);
                gongchengFY=gongchengFY.substr(0,gongchengFY.length-1);

                console.log(gongchengFY,'LKSHAGK')

                $('.survey').val(textareadata);
                var sstr = "";
                var totalMonery = accMul((parseFloat(gongchengKC)+parseFloat(gongchengRS)).toFixed(4) ,10000);

                if ( document.getElementById("dght").checked ){
                    //顶管施工造价
                    //sstr = "顶管施工造价:" + gongchengKC.toFixed(4)+'万元   人手井造价:'+gongchengRS.toFixed(4)+'万元   工程总造价(含税):'+gongchengKC.toFixed(4)+'+'+gongchengRS.toFixed(4)+'='+(parseFloat(gongchengKC)+parseFloat(gongchengRS)).toFixed(4)+'(万元)  '+'  大写:'+changeMoneyToChinese((parseFloat(gongchengKC)+parseFloat(gongchengRS)).toFixed(4)*10000)+'整';
                    sstr = "开槽施工造价:" + gongchengKC.toFixed(4)+'万元   人手井造价:'+gongchengRS.toFixed(4)+'万元   工程造价: ' + gongchengKC.toFixed(4)+'+'+gongchengRS.toFixed(4)+'='+(parseFloat(gongchengKC)+parseFloat(gongchengRS)).toFixed(4)+'(万元)  税费:' + ((parseFloat(gongchengKC)+parseFloat(gongchengRS))*0.1).toFixed(4)+"万元  价税合计：" + ((parseFloat(gongchengKC)+parseFloat(gongchengRS)) + ((parseFloat(gongchengKC)+parseFloat(gongchengRS))*0.1)).toFixed(4)+ "万元";
                }else {
                    //开槽施工造价
                    sstr = "开槽施工造价:" + gongchengKC.toFixed(4)+'万元   人手井造价:'+gongchengRS.toFixed(4)+'万元   工程总造价(含税):'+gongchengKC.toFixed(4)+'+'+gongchengRS.toFixed(4)+'='+(parseFloat(gongchengKC)+parseFloat(gongchengRS)).toFixed(4)+'(万元)  '+'  大写:'+changeMoneyToChinese(totalMonery)+'整';
                }
                $('[name="gcfy"]').val(sstr);
                $('[name="ccPrice"]').val(gongchengFY);

                $('.mask').hide();          //隐藏遮罩层
                $('.mask').hide();          //隐藏遮罩层


            };
            console.log($('.survey').val())
        });         //点击获取全部内容付给外部

        $(document).on('blur','[type="number"]',function () {
            if($(this).val()<0){
                layer.msg('数量不能小于0');
                $(this).val(0);
            }
        })
        //合同编号去重检测
        var time = 0;
        var chushi;
        $("[name='cc_code']").focus(function(){
            $("[name='cc_code']").keyup(function () {
                clearTimeout(time);

                var root = this;
                // 小华更改,128 编辑企业--提交按钮被禁用
                time = setTimeout(function () {
                    var _names=$(root).val();               //获取页面值
                    _names=$.trim(_names);
                    console.log(_names==chushi,'>>>>>>>>>>>>>>>>>>>')
                    var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
                    if(reg.test(_names)){
                        layer.msg('合同单号不能包含汉字');
                        Btnon('.tijiao');
                        return;
                    }else{
                        Btnoff('.tijiao');
                    }

                    if(_names){
                        if(_names==chushi){
                            return;
                        }
                        ajaxs('/api/public/cheName.do','get',{"type":4,"name":_names},function (data) {
                            console.log(data)
                            if(data.data=='0'){
//                            layer.msg('企业名可用');
                                $('.tijiao').removeAttr('disabled').removeClass('layui-btn-disabled');
                            }else{
                                layer.msg('合同编号已存在 请重新输入');
                                $('.tijiao').attr('disabled',"true").addClass('layui-btn-disabled');
                            }
                        })
                    }
                }, 500)

            })
        })

        /*<---------------遮罩层内容*/
        form.on('submit(formDemo)', function(data){
            console.log(data.elem) //被执行事件的万元素DOM对象，一般为button对象
            console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            Btnon('.tijiao');
            data.field.p=getCookie('yanzheng');
            data.field.oprice=kaicao;
            data.field.hprice=renshoujing;
            data.field.cType= 2;
            data.field.compcode1=$('[name="compname1"]').find("option:selected").attr("code");
            data.field.old_code=ourCode;
            tiaoAlertAjax('/api/contract/updateContcract.do',data.field,'.tijiao');

            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    });
</script>

</body>
</html>